package com.joolun.web.controller.activity;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.joolun.common.annotation.Log;
import com.joolun.common.core.controller.BaseController;
import com.joolun.common.core.domain.AjaxResult;
import com.joolun.common.enums.BusinessType;
import com.joolun.activity.domain.ActivityAward;
import com.joolun.activity.service.IActivityAwardService;
import com.joolun.common.utils.poi.ExcelUtil;
import com.joolun.common.core.page.TableDataInfo;

/**
 * 活动奖品Controller
 *
 * @author www.joolun.com
 * @date 2022-11-22
 */
@RestController
@RequestMapping("/activity/award")
public class ActivityAwardController extends BaseController
{
    @Autowired
    private IActivityAwardService activityAwardService;

    /**
     * 查询活动奖品列表
     */
    @PreAuthorize("@ss.hasPermi('activity:award:list')")
    @GetMapping("/list")
    public TableDataInfo list(ActivityAward activityAward)
    {
        startPage();
        List<ActivityAward> list = activityAwardService.selectActivityAwardList(activityAward);
        return getDataTable(list);
    }

    /**
     * 导出活动奖品列表
     */
    @PreAuthorize("@ss.hasPermi('activity:award:export')")
    @Log(title = "活动奖品", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ActivityAward activityAward)
    {
        List<ActivityAward> list = activityAwardService.selectActivityAwardList(activityAward);
        ExcelUtil<ActivityAward> util = new ExcelUtil<ActivityAward>(ActivityAward.class);
        return util.exportExcel(list, "award");
    }

    /**
     * 获取活动奖品详细信息
     */
    @PreAuthorize("@ss.hasPermi('activity:award:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(activityAwardService.selectActivityAwardById(id));
    }

    /**
     * 新增活动奖品
     */
    @PreAuthorize("@ss.hasPermi('activity:award:add')")
    @Log(title = "活动奖品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ActivityAward activityAward)
    {
        return toAjax(activityAwardService.insertActivityAward(activityAward));
    }

    /**
     * 修改活动奖品
     */
    @PreAuthorize("@ss.hasPermi('activity:award:edit')")
    @Log(title = "活动奖品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ActivityAward activityAward)
    {
        return toAjax(activityAwardService.updateActivityAward(activityAward));
    }

    /**
     * 删除活动奖品
     */
    @PreAuthorize("@ss.hasPermi('activity:award:remove')")
    @Log(title = "活动奖品", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(activityAwardService.deleteActivityAwardByIds(ids));
    }
}
